<?php
namespace Admin\Models\stats;

use Admin\Models\BaseModel;

class XhstatsWelfare extends BaseModel
{

    /**
     *
     * @var integer
     * @Primary
     * @Identity
     * @Column(type="integer", length=11, nullable=false)
     */
    public $iSWId;

    /**
     *
     * @var integer
     * @Column(type="integer", length=20, nullable=true)
     */
    public $iUserId;

    /**
     *
     * @var integer
     * @Column(type="integer", length=11, nullable=true)
     */
    public $iType;

    /**
     *
     * @var integer
     * @Column(type="integer", length=4, nullable=true)
     */
    public $bQuit;

    /**
     *
     * @var string
     * @Column(type="string", length=20, nullable=true)
     */
    public $sPhoneNum;

    /**
     *
     * @var string
     * @Column(type="string", length=255, nullable=true)
     */
    public $sExtraVal1;

    /**
     *
     * @var string
     * @Column(type="string", length=255, nullable=true)
     */
    public $sExtraVal2;

    /**
     *
     * @var string
     * @Column(type="string", length=255, nullable=true)
     */
    public $sExtraVal3;

    /**
     *
     * @var integer
     * @Column(type="integer", length=4, nullable=true)
     */
    public $bDelete;

    /**
     *
     * @var integer
     * @Column(type="integer", length=20, nullable=true)
     */
    public $iCreateUserId;

    /**
     *
     * @var string
     * @Column(type="string", nullable=true)
     */
    public $tCreateDate;

    /**
     *
     * @var integer
     * @Column(type="integer", length=20, nullable=true)
     */
    public $iLastModifyUserId;

    /**
     *
     * @var string
     * @Column(type="string", nullable=true)
     */
    public $tLastModifyDate;

    /**
     * Initialize method for model.
     */
    public function initialize()
    {
        parent::initialize();
    }

    /**
     * Returns table name mapped in the model.
     *
     * @return string
     */
    public function getSource()
    {
        return 'XHStats_Welfare';
    }

    /**
     * Allows to query a set of records that match the specified conditions
     *
     * @param mixed $parameters
     * @return XhstatsWelfare[]|XhstatsWelfare
     */
    public static function find($parameters = null)
    {
        return parent::find($parameters);
    }

    /**
     * Allows to query the first record that match the specified conditions
     *
     * @param mixed $parameters
     * @return XhstatsWelfare
     */
    public static function findFirst($parameters = null)
    {
        return parent::findFirst($parameters);
    }

    /**
     * 检查是否提交
     *
     * @param $userId
     * @param $type
     * @return bool
     *
     * create by ck 20180208
     */
    public static function checkExist($userId, $type)
    {
        return !!self::count([
            'conditions' => 'bDelete = 0 AND iUserId = :userId: AND iType = :type:',
            'bind'       => ['userId' => $userId, 'type' => $type]
        ]);
    }

}
